﻿@using DNA.OpenAPI.Atom;
@model IEnumerable<AtomEntry>
@{
    Ajax.Dna().Accordion()
           .Options(opts =>
           {
               opts.Icons = new AccordionOptions.HeaderIconsStyle()
               {
                   HeaderCssClass = "d-accordion-icon",
                   HeaderSelectedIconCssClass = "d-accordion-icon-select"
               };
               opts.AutoHeight = false;
               opts.Navigation = true;
           })
           .Name("Accordion_" + Guid.NewGuid().ToString().Substring(0, 5))
           .Sections(sections =>
           {
               foreach (var entry in Model)
               {
                   var _textLen = (int)ViewData["TextLen"];
                   var _postTitle = entry.Title;
                   var _showAuthor = (bool)ViewData["ShowAuthor"];
                   var _showDate = (bool)ViewData["ShowDate"];
                   var atomEntry = entry;
                   _postTitle = Html.Cut(_postTitle, _textLen);
                   sections.Add(_postTitle).Template(@<text>
    <table style="width: 100%;">
        @if (_showAuthor || _showDate)
        {
            <tr>
                <td colspan="2">
                    <ul class="d-horizontal-list">
                        @if ((bool)ViewData["ShowAuthor"] && !string.IsNullOrEmpty(atomEntry.Author.Name))
                        {  
                            <li style="color: #cccccc; font-style: italic">@Html.Global("RES_POSTBY") <a href="@(string.IsNullOrEmpty(atomEntry.Author.Uri) ? "javascript:void(0);" : atomEntry.Author.Uri)" rel="nofollow" target="_blank">@item.Author.Name</a>
                            </li>
                        }
                        @if ((bool)ViewData["ShowDate"])
                        { 
                            <li style="color: #cccccc; font-style: italic">
                                @Html.Global(atomEntry.Published)
                            </li>
                        }
                        @if ((atomEntry.Categories != null) && (atomEntry.Categories.Count > 0))
                        {
                            foreach (var c in atomEntry.Categories)
                            {
                            <li><a href="@(string.IsNullOrEmpty(c.Scheme) ? "javascript:void(0);" : c.Scheme)">@(string.IsNullOrEmpty(c.Text) ? c.Term : c.Text)</a></li>
                            }
                        }
                    </ul>
                </td>
            </tr>
        }
        <tr>
            <td style="vertical-align: top;">
                @if (atomEntry.Links != null)
                {
                    var imgLink = atomEntry.Links.Where(l => l.Type.StartsWith("image")).FirstOrDefault();

                    if (!string.IsNullOrEmpty(imgLink.NavigateUrl))
                    {
                    <div class="d-avatar">
                        <img src="@imgLink.NavigateUrl" alt="@imgLink.Text" />
                    </div>
                    }
                }
            </td>
            <td style="vertical-align: top;">
                <p class="d-post-summary" title="@atomEntry.Summary" style="margin:0px;">
                    @if (!string.IsNullOrEmpty(atomEntry.Summary))
                    {
                        @Html.Cut(TextEngine.Text(atomEntry.Summary), 255)
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(atomEntry.Content.Text))
                        {
                        @Html.Cut(TextEngine.Text(atomEntry.Content.Text), 255)
                        }
                    }
                </p>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: right;">
                <a href="@atomEntry.ID" class="d-link" rel="nofollow" target="_blank" >@Html.Global("RES_MORE")</a>
            </td>
        </tr>
    </table>
    </text>);
               }
           }).Render();
}
@Html.StartupScripts()
